#include <iostream>
#include <stack>

using namespace std;

int compareFunc(const void* a, const void* b)
{
	return (*(int*)a) - (*(int*)b);
}

int main(int argc, char* argv[])
{
	int stampSet[100];
	int customers[100];
	while(true) {
		int setSize = 0;
		int stamp = 0;
		cin>>stamp;
		while (stamp != 0) {
			stampSet[setSize++] = stamp;
			cin>>stamp;
		}

		int customerSize = 0;
		int customerRequest = 0;
		cin>>customerRequest;
		while (customerRequest != 0) {
			customers[customerSize++] = customerRequest;
			cin>>customerRequest;
		}
		qsort(stampSet, setSize, sizeof(int), compareFunc);

		// Start to handle each customer's request
		for (int i = 0; i < customerSize; i++) {
			int typeSold = 0;
			int numSold = 0;
			int customer = customers[i];
			/*int j = setSize - 1;
			for (; j >= 0; --j) {
				if (stampSet[j] <= customer) {
					++typeSold;
					customer -= stampSet[j];
					if (customer == 0 && typeSold <= 4)
						break;
					else if (customer == 0) {

					}
				}
			}

			if (j < 0) {
				cout<<customers[i]<<" ---- none";
			} else {

			}*/
			int j = -1;
			stack<int> sta;
			sta.push(j);
			/*for (; j < setSize; j++) {
				if (stampSet[j] > customer) {

				}
			}*/
			while (!sta.empty()) {
				j = sta.top() + 1;
				if (j == 0) {
					sta.pop();
				} else if (j >= setSize && customer > 0) {
					j = 0;
				}

				if (stampSet[j] > customer && j == 0)
				{
					cout<<customers[i]<<" ---- none"<<endl;
					break;
				} else if (stampSet[j] > customer && customer > 0) {
					// Backdate
					sta.pop();
				} else if (stampSet[j] > customer && numSold > 4) {
					sta.pop();
				} else if (stampSet[j] > customer) {
					// Found it
					cout<<customers[i]<<"("<<typeSold<<"):";
					while (!sta.empty()) {
						cout<<" "<<stampSet[sta.top()];
						sta.pop();
					}
					cout<<endl;					
					break;
				} else if (stampSet[j] <= customer && numSold < 4) {
					customer -= stampSet[j];
					sta.push(j);
					++numSold;
				}

			}
		}
		
	}
	return 0;
}